package com.sunday.boot3.user.center.rest.api.impl;

import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.boot3.user.center.controller.RoleController;
import com.sunday.boot3.user.center.pojo.dto.role.SaveRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.RemoveRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.UpdateRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.PageRoleReqDTO;
import com.sunday.boot3.user.center.rest.vo.role.PageRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.role.RemoveRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.role.PageRoleResVO;
import com.sunday.boot3.user.center.rest.vo.role.SaveRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.role.UpdateRoleReqVO;
import com.sunday.boot3.user.center.rest.api.RoleApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 角色表 Web impl 层
 * @author: zsy
 * @Create: 2024/09/22 16:24:39
 */
@Slf4j
@RestController
@RequestMapping(RoleApi.ACCESS_PATH)
@RequiredArgsConstructor
public class RoleApiImpl implements RoleApi {

    private final RoleController roleController;

    /**
     * @Description: 新增 角色表 数据
     * @Param: [saveRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse save(SaveRoleReqVO saveRoleReqVO) {
        return RestResponse.resultReturn(roleController.save(MapperConvert.map(saveRoleReqVO, SaveRoleReqDTO.class)));
    }

    /**
     * @Description: 删除 角色表 数据
     * @Param: [removeRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse remove(RemoveRoleReqVO removeRoleReqVO) {
        return RestResponse.resultReturn(roleController.remove(MapperConvert.map(removeRoleReqVO, RemoveRoleReqDTO.class)));
    }

    /**
     * @Description: 修改 角色表 数据
     *
     * @Param: [updateRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse update(UpdateRoleReqVO updateRoleReqVO) {
        return RestResponse.resultReturn(roleController.update(MapperConvert.map(updateRoleReqVO, UpdateRoleReqDTO.class)));
    }

    /**
    * @Description: 获取 角色表 分页列表数据
    *
    * @Param: [pageRoleReqVO]
    * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.fegin.FeginPageResultVO<com.sunday.boot3.user.center.rest.vo.role.PageRoleResVO>>
    * @author: zsy
    * @Create: 2024/09/22 16:24:39
    */
    @Override
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    public RestResponse<PageVO<PageRoleResVO>> page(PageRoleReqVO pageRoleReqVO) {
        return RestResponse.convertResultReturn(
                roleController.page(MapperConvert.map(pageRoleReqVO, PageRoleReqDTO.class)),
                body -> PageVO.of(body, PageRoleResVO.class));
    }

}